let dragons = require('dragons');
let bones = require('bones');
cc.Class({
    extends: cc.Component,

    properties: {
        dragStartAnimation:'',
        dragEndAnimation:'',
        dragIdleAnimation:'',
        moveTime:0.3,
        dragTarget:cc.Node,
        animationNode:cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.orginPostion = this.node.position;
        if (!self.dragStartAnimation){
            self.dragStartAnimation = bones.TS_01_CLICK;
        }
        if (!self.dragIdleAnimation){
            self.dragIdleAnimation = bones.TS_01_IDLE;
        }
    },
    start () {
        this._tipsStart();
    },
    _tipsStart(){
        let self = this;
        if (self.dragStartAnimation){
            dragons.playAnimation(self.animationNode,self.dragStartAnimation,1,function () {
                self._tipsMove();
            });
        }else{
            self._tipsMove();
        }
    },
    _tipsMove(){
        let self = this;
        if (self.dragIdleAnimation){
            dragons.playAnimation(self.animationNode,self.dragIdleAnimation,0);
        }
        let moveTo = cc.moveBy(self.moveTime,-200,150);
        let callback = cc.callFunc(function () {
            self._tipsEnd();
        })
        this.node.runAction(cc.sequence(moveTo,callback))
    },
    _tipsEnd(){
        let self = this;
        if (self.dragEndAnimation){
            dragons.playAnimation(self.animationNode,self.dragIdleAnimation,1,function () {
                self.node.position = self.orginPostion;
            });
        }else{
            self.node.position = self.orginPostion;
        }
        self._tipsStart();
    }
    // update (dt) {},
});
